package com.woniuxy.cloud.userassembly.service.impl;

import com.alibaba.druid.util.Utils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.cloud.entity.TUserAddress;
import com.woniuxy.cloud.form.UpdateUserAddressForm;
import com.woniuxy.cloud.form.UserAddressForm;
import com.woniuxy.cloud.userassembly.mapper.TUserAddressMapper;
import com.woniuxy.cloud.userassembly.service.ITUserAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户地址表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-24
 */
@Slf4j
@Service
public class TUserAddressServiceImpl extends ServiceImpl<TUserAddressMapper, TUserAddress> implements ITUserAddressService {

    /**
     * 新增收货地址
     * @param userAddressForm
     * @return Result
     */
    @Override
    public Integer addUserAddress(UserAddressForm userAddressForm) {
        TUserAddress tUserAddress = new TUserAddress();
        tUserAddress.setUserAddressUserId(userAddressForm.getUserId()).setUserAddressName(userAddressForm.getAddressName()).setUserAddressUserNickName(userAddressForm.getUserNickName()).setUserAddressPhone(userAddressForm.getAddressPhone());

        return  getBaseMapper().insert(tUserAddress);
    }

    @Override
    public List<TUserAddress> getUserAddressListByUserId(Integer userId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_address_user_id",userId);
        return  getBaseMapper().selectList(wrapper);
    }

    @Override
    public Integer updateUserAddress(UpdateUserAddressForm updateUserAddressForm) {
        TUserAddress tUserAddress = new TUserAddress();
        tUserAddress.setUserAddressPhone(updateUserAddressForm.getAddressPhone()).setUserAddressUserNickName(updateUserAddressForm.getUserNickName()).setUserAddressName(updateUserAddressForm.getAddressName()).setUserAddressId(updateUserAddressForm.getUserAddressId());
        log.info("{}",tUserAddress);
        return getBaseMapper().updateById(tUserAddress);
    }

    @Override
    public Integer deleteUserAddressById(Integer userAddressId) {
        return  getBaseMapper().deleteById(userAddressId);
    }

    @Override
    public TUserAddress getUserAddressById(Integer userAddressId) {
        return getBaseMapper().selectById(userAddressId);
    }


}
